package layeredcontent.domains.account.commands
{
	import flash.events.Event;
	
	import flight.domain.AsyncCommand;
	
	import layeredcontent.domains.account.AccountDomain;
	import layeredcontent.domains.account.views.CreateAccountWindow;
	
	import withincode.db.Database;

	public class CommandNewAccount extends AsyncCommand
	{
		public var client:AccountDomain;
		protected var window:CreateAccountWindow;
		protected var database:Database;
		
		public override function execute():void
		{
			window = new CreateAccountWindow();
			window.addEventListener(Event.COMPLETE, onComplete);
			window.addEventListener(Event.CANCEL, onCancel);
			window.addEventListener(Event.CLOSE, onCancel);
			window.open();
		}
		
		
		protected function onCancel(event:Event):void
		{
			if (event.type != Event.CLOSE) {
				window.close();
			}
			cancel();
		}
		
		
		protected function onComplete(event:Event):void
		{
			window.removeEventListener(Event.CLOSE, onCancel);
//			window.account.save();
			complete();
		}
	}
}